# EEG_ADC

This Python script converts scanned EEG recording produced by ECT machines, e.g. Thymatron.

Digitized EEG signal is further analyzed: mainly spectrum and power spectrum are calculated for the whole signal and all EEG bands.

## Installation

Download and unzip the repository from: https://notabug.org/AdamWysokinski/EEG_ADC/archive/master.zip or clone it using git:

    $ git clone https://notabug.org/AdamWysokinski/EEG_ADC

Python 3 and the following Python modules are required:
- Matplotlib
- NumPy
- pandas
- SciPy
- skimage

## Usage

Example input file:
![example.png](https://notabug.org/AdamWysokinski/EEG_ADC/src/master/example/example.png)

The scanned input image (PNG preferably) has to be:
- DPI: 100
- resolution: 490×100 pixels
- dimensions on paper: height 2.5 cm, width 12.5 cm

The program tries to eliminate noise, background grid, etc. In order to get best results you may also manually remove them using any image editor, e.g. free and open-source [GIMP](https://www.gimp.org).

To analyze the scanned image, run the program as:

    $ ./eeg_adc.py file_name.png

After processing, the following output files are produced:
1. binary (black and white) version of the input image: file_name-bw.png
2. digitized signal: file_name-signal.csv (with two columns: time and amplitude)
3. signal plot: file_name-signal.pdf
4. signal spectrum: file_name-fft.pdf
5. power spectrum: file_name-psd.pdf
6. absolute power across EEG bands: file_name-bands.cvs (with two columns: band name and absolute power in μV^2/Hz)
7. absolute power across EEG bands bar plot: file_name-bands.pdf
8. summary report (signal filename, max, min, mean and median amplitudes, absolute power, absolute and relative powers across EEG bands): file_name-report.txt

Output files are stored in the same directory as the input file. **Important:** old output files are overwritten without prompting!

Below is a typical session:

    $ ./eeg_adc.py example/example.png

    EEG-ADC analyzer v1.0
    =====================

    Imported modules:
     Matplotlib 3.3.4
          NumPy 1.19.5
         pandas 1.1.5
          SciPy 1.6.0
        skimage 0.18.3

    Reading input image: example/example.png

    Interpolate and digitize..
    Saving PNG: example/example-bw.png
    Saving CSV: example/example-signal.csv
    Applying HP filter at 0.5 Hz..
    Calculating FFT..
    Calculating PSD..
    Saving PDF: example/example-signal.pdf
    Saving PDF: example/example-fft.pdf
    Saving PDF: example/example-psd.pdf
    Saving PDF: example/example-bands.pdf
    Saving CSV: example/example-bands.csv
    Saving TXT: example/example-report.txt

    Analysis completed.

## TODO

* input argument for user-defined px_uv and px_s (p1)
* input image of any dimensions and DPI (p2)

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request

## History

v1.0 (06/10/2021) First official release.

## Credits

Author: Prof. Adam Wysokiński (adam.wysokinski AT umed.lodz.pl)

Department of Old Age Psychiatry and Psychotic Disorders

Medical University of Lodz, Poland

## License

This software is licensed under [The 2-Clause BSD License](LICENSE).